public class ThreadDemo3 {
    public static void main(String[] args) throws InterruptedException {
        Object lock=new Object();
        Thread t1=new Thread(()->{
            synchronized (lock) {
                System.out.println("你下班了吗？你下班了，我就来上班");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("那我来上班了");
            }
        });
        Thread t2=new Thread(()->{
            synchronized (lock){
                System.out.println("我下班了");
                lock.notify();
            }
        });
        t1.start();
        Thread.sleep(200);
        t2.start();
    }
    public static void main1(String[] args) throws InterruptedException {
        Object lock=new Object();
        Thread t=new Thread(()->{
            synchronized (lock){
                System.out.println("我这个部分已经干完了");
                System.out.println("我只等你一个小时");
                try {
                    lock.wait(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t.start();
        Thread.sleep(1000);//为了让t 线程先运行
        System.out.println("别急，我正在努力赶");
    }
}
